package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.grade.domain.Grade;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.Classper;
import com.ruoyi.stuinfo.service.IClassperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课堂记录Controller
 *
 * @author zc
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/stuinfo/classper")
public class ClassperController extends BaseController
{
    @Autowired
    private IClassperService classperService;

    /**
     * 查询课堂记录列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:classper:list')")
    @GetMapping("/list")
    public TableDataInfo list(Classper classper)
    {

        String teacherId=getUsername();
        boolean hasH = teacherId.contains("H");
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<Classper> list = classperService.selectClassperList(classper);
            return getDataTable(list);
        }
        else if(hasH)
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            startPage();
            List<Classper> list = classperService.selectClassperList_handteacher(teacherId);
            return getDataTable(list);
        }
        else
        {
            //教师
            startPage();
            List<Classper> list = classperService.selectClassperList_teacher(teacherId);
            return getDataTable(list);
        }

    }

    /**
     * 导出课堂记录列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:classper:export')")
    @Log(title = "课堂记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Classper classper)
    {

        String teacherId=getUsername();
        boolean hasH = teacherId.contains("H");
        if("admin".equals(teacherId))
        {
            //管理员
            List<Classper> list = classperService.selectClassperList(classper);
            ExcelUtil<Classper> util = new ExcelUtil<Classper>(Classper.class);
            util.exportExcel(response, list, "课堂记录数据");
        }
        else if(hasH)
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            List<Classper> list = classperService.selectClassperList_handteacher(teacherId);
            ExcelUtil<Classper> util = new ExcelUtil<Classper>(Classper.class);
            util.exportExcel(response, list, "课堂记录数据");
        }
        else
        {
            //教师
            List<Classper> list = classperService.selectClassperList_teacher(teacherId);
            ExcelUtil<Classper> util = new ExcelUtil<Classper>(Classper.class);
            util.exportExcel(response, list, "课堂记录数据");
        }

    }

    /**
     * 获取课堂记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:classper:query')")
    @GetMapping(value = "/{performanceId}")
    public AjaxResult getInfo(@PathVariable("performanceId") Long performanceId)
    {
        return success(classperService.selectClassperByPerformanceId(performanceId));
    }

    /**
     * 新增课堂记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:classper:add')")
    @Log(title = "课堂记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Classper classper)
    {
        return toAjax(classperService.insertClassper(classper));
    }

    /**
     * 修改课堂记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:classper:edit')")
    @Log(title = "课堂记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Classper classper)
    {
        return toAjax(classperService.updateClassper(classper));
    }

    /**
     * 删除课堂记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:classper:remove')")
    @Log(title = "课堂记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{performanceIds}")
    public AjaxResult remove(@PathVariable Long[] performanceIds)
    {
        return toAjax(classperService.deleteClassperByPerformanceIds(performanceIds));
    }
}
